var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "./CryptoUtil"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    const CryptoUtil_1 = __importDefault(require("./CryptoUtil"));
    function getImageSuffix(fileBuffer) {
        const imageBufferHeaders = [
            { bufBegin: [0xff, 0xd8], bufEnd: [0xff, 0xd9], suffix: '.jpg' },
            { bufBegin: [0x00, 0x00, 0x02, 0x00, 0x00], suffix: '.tga' },
            { bufBegin: [0x00, 0x00, 0x10, 0x00, 0x00], suffix: '.rle' },
            {
                bufBegin: [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a],
                suffix: '.png'
            },
            { bufBegin: [0x47, 0x49, 0x46, 0x38, 0x39, 0x61], suffix: '.gif' },
            { bufBegin: [0x47, 0x49, 0x46, 0x38, 0x37, 0x61], suffix: '.gif' },
            { bufBegin: [0x42, 0x4d], suffix: '.bmp' },
            { bufBegin: [0x0a], suffix: '.pcx' },
            { bufBegin: [0x49, 0x49], suffix: '.tif' },
            { bufBegin: [0x4d, 0x4d], suffix: '.tif' },
            {
                bufBegin: [0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x20, 0x20],
                suffix: '.ico'
            },
            {
                bufBegin: [0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x20, 0x20],
                suffix: '.cur'
            },
            { bufBegin: [0x46, 0x4f, 0x52, 0x4d], suffix: '.iff' },
            { bufBegin: [0x52, 0x49, 0x46, 0x46], suffix: '.ani' }
        ];
        for (const imageBufferHeader of imageBufferHeaders) {
            let isEqual;
            if (imageBufferHeader.bufBegin) {
                const buf = Buffer.from(imageBufferHeader.bufBegin);
                isEqual = buf.equals(fileBuffer.slice(0, imageBufferHeader.bufBegin.length));
            }
            if (isEqual && imageBufferHeader.bufEnd) {
                const buf = Buffer.from(imageBufferHeader.bufEnd);
                isEqual = buf.equals(fileBuffer.slice(-imageBufferHeader.bufEnd.length));
            }
            if (isEqual) {
                return imageBufferHeader.suffix;
            }
        }
        return '';
    }
    exports.default = CryptoUtil_1.default;
});
